bitkeeper revision 1.1159.14.2 (4118cb0281sulMDs4loWPr772DRiNA)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Tue, 10 Aug 2004 13:17:54 +0000 (13:17 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Tue, 10 Aug 2004 13:17:54 +0000 (13:17 +0000)
Fix save/restore of the vm config and rebuilding a restored domain.

tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/xfrd/xen_domain.c

index dbf0ce6e90daa8cdff58d991b0b3dc287724815b..7ae079734ff11b8bed29e6217be7779d5b1dc0a9 100644 (file)
@@ -413,10 +413,7 @@ class XendDomain:
 
     def domain_exists(self, name):
         name = str(name)
-        if self.domain_by_name.get(name) or self.domain_by_id.get(name):
-            return 1
-        else:
-            return 0
+        return self.domain_by_name.get(name) or self.domain_by_id.get(name):
 
     def domain_unpause(self, id):
         """Unpause domain execution.
index 04792c48eb56dd34b764ac7913452c699efe242b..cda3de9b30a4d7f739715ec64e5cffd675e8345d 100644 (file)
@@ -295,15 +295,20 @@ def vm_restore(src, progress=0):
     raises   VmError for invalid configuration
     """
     vm = XendDomainInfo()
+    vm.restore = 1
     ostype = "linux" #todo Set from somewhere (store in the src?).
     restorefn = getattr(xc, "%s_restore" % ostype)
     d = restorefn(state_file=src, progress=progress)
     dom = int(d['dom'])
     if dom < 0:
         raise VmError('restore failed')
-    vmconfig = sxp.from_string(d['vmconfig'])
-    vm.config = sxp.child_value(vmconfig, 'config')
-    deferred = vm.dom_configure(dom)
+    try:
+        vmconfig = sxp.from_string(d['vmconfig'])
+        vm.config = sxp.child_value(vmconfig, 'config')
+    except Exception, ex:
+        raise VmError('config error: ' + str(ex))
+    deferred = vm.dom_construct(dom)
+    vm.restore = 0
     def vifs_cb(val, vm):
         vif_up(vm.ipaddrs)
     deferred.addCallback(vifs_cb, vm)
@@ -354,6 +359,7 @@ class XendDomainInfo:
 
     def __init__(self):
         self.recreate = 0
+        self.restore = 0
         self.config = None
         self.id = None
         self.dom = None
@@ -463,7 +469,11 @@ class XendDomainInfo:
             raise VmError('invalid vm name')
         # See comment in XendDomain constructor.
         xd = get_component('xen.xend.XendDomain')
-        if xd.domain_exists(name):
+        dominfo = xd.domain_exists(name)
+        # When creating or rebooting, a domain with my name should not exist.
+        # When restoring, a domain with my name will exist, but it should have
+        # my domain id.
+        if dominfo and (not self.dom or dominfo.dom != self.dom)
             raise VmError('vm name clash: ' + name)
         
     def construct(self, config):
@@ -688,7 +698,12 @@ class XendDomainInfo:
     def init_domain(self):
         """Initialize the domain memory.
         """
-        if self.recreate: return
+        if self.recreate:
+            return
+        if self.start_time is None:
+            self.start_time = time.time()
+        if self.restore:
+            return
         memory = self.memory
         name = self.name
         cpu = int(sxp.child_value(self.config, 'cpu', '-1'))
@@ -700,9 +715,6 @@ class XendDomainInfo:
         log.debug('init_domain> Created domain=%d name=%s memory=%d', dom, name, memory)
         self.setdom(dom)
 
-        if self.start_time is None:
-            self.start_time = time.time()
-
     def build_domain(self, ostype, kernel, ramdisk, cmdline, vifs_n):
         """Build the domain boot image.
         """
@@ -918,8 +930,8 @@ class XendDomainInfo:
         d.addCallback(_vm_configure1, self)
         return d
 
-    def dom_configure(self, dom):
-        """Configure a vm for an existing domain.
+    def dom_construct(self, dom):
+        """Construct a vm for an existing domain.
 
         @param dom:    domain id
         @return: deferred
@@ -931,7 +943,7 @@ class XendDomainInfo:
             self.setdom(dom)
             self.name = d['name']
             self.memory = d['memory']/1024
-            deferred = self.configure()
+            deferred = self.construct()
             def cberr(err):
                 self.destroy()
                 return err
index a3e270518ed658e4dc593ac67051fa492ac77b3d..e1dacb333f41373cd45369cf459876670d590f0a 100644 (file)
@@ -81,13 +81,14 @@ int xen_domain_snd(Conn *xend, IOStream *io, uint32_t dom, char *vmconfig, int v
   exit:
 #else 
     XcIOContext _ioctxt = {}, *ioctxt = &_ioctxt;
-    dprintf("> dom=%d\n", dom);
     ioctxt->domain = dom;
     ioctxt->io = io;
     ioctxt->info = iostdout;
     ioctxt->err = iostderr;
     ioctxt->data = xend;
     ioctxt->suspend = domain_suspend;
+    ioctxt->vmconfig = vmconfig;
+    ioctxt->vmconfig_n = vmconfig_n;
 
     err = xc_linux_save(xcinit(), ioctxt);
 #endif